home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.05 May 91 / Math Parser ƒ / Node Stuff / EvaluateNodes < prev    next >
Encoding:
Text File  |  1990-10-31  |  2.4 KB  |  103 lines  |  [TEXT/PJMM]

  1. unit EvaluateNodes;
  2.  
  3. interface
  4.  
  5.     uses
  6.         ParserGlobals, Operations;
  7.  
  8.     procedure evaluatenodes (var nodetable: hdlnoderecord; var numnodes: integer; var t: hdlextendarray; var store: boolean; var save: array2; var error: str255);
  9.  
  10. implementation
  11.  
  12.  
  13.     procedure evaluatenodes;
  14.  
  15.  
  16.         label
  17.             777, 999;
  18.  
  19.         var
  20.             i, j, k, l, m, n: integer;
  21.             realbinoperator, realfunctiontype: stringsize;
  22.             b1, b2, b3: extended;
  23.             s1, s2, s3, s4: boolean;
  24.  
  25.     begin
  26.  
  27.         for i := 1 to numnodes do
  28.             begin
  29.                 with nodetable^^[i] do
  30.                     begin
  31.  
  32.                         s1 := (nodetable^^[i].lop.index <> save[1]);
  33.                         s2 := ((nodetable^^[i].lop.index = save[1]) and (save[2] <> equals));
  34.                         s3 := (nodetable^^[i].loptype = 'real') or (nodetable^^[i].loptype = 'constant') or (nodetable^^[i].loptype = 'node');
  35.                         s4 := (nodetable^^[i].roptype = 'real') or (nodetable^^[i].roptype = 'constant') or (nodetable^^[i].roptype = 'node');
  36.  
  37.                         if (s1 or s2) and s3 then
  38.                             readstring(nodetable^^[i].lop.index, b1);
  39.  
  40.                         if loptype = 'node' then
  41.                             b1 := t^^[round(b1)];
  42.  
  43.                         if s4 then
  44.                             readstring(nodetable^^[i].rop.index, b2);
  45.  
  46.                         if roptype = 'node' then
  47.                             b2 := t^^[round(b2)];
  48.  
  49.                         if (nodetable^^[i].op.index = equals) then
  50.                             begin
  51.                                 t^^[i] := b2;
  52.                                 goto 777;
  53.                             end;
  54.  
  55.                     end;
  56.  
  57.  
  58. 777:
  59.                 if (nodetable^^[i].optype = 'binary') then
  60.                     begin
  61.                         realbinoperator := nodetable^^[i].op.index;
  62.                         realbinaryoperations(realbinoperator, b1, b2, b3, error);
  63.                     end;
  64.                 if nodetable^^[i].optype = 'function' then
  65.                     begin
  66.                         realbinoperator := nodetable^^[i].op.index;
  67.                         realfunctiontype := 'function';
  68.                         realfunctionoperations(realfunctiontype, realbinoperator, b1, b2, b3, error);
  69.                     end;
  70.                 if nodetable^^[i].optype = 'unary' then
  71.                     begin
  72.                         realbinoperator := nodetable^^[i].op.index;
  73.                         realfunctiontype := 'unary';
  74.                         realfunctionoperations(realfunctiontype, realbinoperator, b1, b2, b3, error);
  75.                     end;
  76.                 t^^[i] := b3;
  77.             end;
  78.  
  79.         numvariables := numvariables + 1;
  80.         strvar^^[numvariables] := 'ans';
  81.         if numnodes > 0 then
  82.             begin
  83.                 val^^[numvariables] := t^^[numnodes];
  84.                 strvartokentype^^[numvariables] := 'real';
  85.             end;
  86.  
  87.  
  88.         if store then
  89.             begin
  90.                 numvariables := numvariables + 1;
  91.                 strvar^^[numvariables] := save[1];
  92.                 if numnodes > 0 then
  93.                     begin
  94.                         val^^[numvariables] := t^^[numnodes];
  95.                         strvartokentype^^[numvariables] := 'real';
  96.                     end;
  97.             end;
  98.  
  99. 999:
  100.     end;
  101.  
  102.  
  103. end.